import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:oli/widget/AvatarWidget.dart';
import 'package:oli/widget/LevelWidget.dart';
import 'package:oli/router/MainRoutePath.dart';

class UserInfoHeader extends StatelessWidget {
  final String? nickname;
  final String? avatarUrl;
  final int? memberLevel;
  final Function()? onLevelTap;
  final bool isLoggedIn;

  const UserInfoHeader({
    super.key,
    this.nickname,
    this.avatarUrl,
    this.memberLevel,
    this.onLevelTap,
    required this.isLoggedIn,
  });

  @override
  Widget build(BuildContext context) {
    if (!isLoggedIn) {
      return Padding(
        padding: const EdgeInsets.symmetric(horizontal: 20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              '您还未登录',
              style: TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
                color: const Color(0xFFD4AF37),
                shadows: [
                  Shadow(
                    color: Colors.grey.withOpacity(0.3),
                    blurRadius: 3,
                    offset: const Offset(0, 2),
                  ),
                ],
              ),
            ),
            const SizedBox(height: 15),
            ElevatedButton(
              onPressed: () {
                Get.toNamed(MainRoutePath.logic);
                print('点击登录');
              },
              style: ElevatedButton.styleFrom(
                backgroundColor: const Color(0xFFD4AF37),
                foregroundColor: Colors.white,
                padding: const EdgeInsets.symmetric(
                  horizontal: 30,
                  vertical: 12,
                ),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(8),
                ),
              ),
              child: const Text(
                '点击登录',
                style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
              ),
            ),
          ],
        ),
      );
    }

    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 20),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          AvatarWidget(avatarUrl: avatarUrl!),
          const SizedBox(width: 20),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Text(
                    nickname!,
                    style: TextStyle(
                      fontSize: 24,
                      fontWeight: FontWeight.bold,
                      color: const Color(0xFFD4AF37),
                      fontFamily: 'ZhiMangXing',
                      shadows: [
                        Shadow(
                          color: Colors.grey.withOpacity(0.3),
                          blurRadius: 3,
                          offset: const Offset(0, 2),
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(width: 10),
                  LevelWidget(memberLevel: memberLevel!, onTap: onLevelTap!),
                ],
              ),
              const SizedBox(height: 10),
              const Text(
                '一位热爱汽车的人',
                style: TextStyle(fontSize: 16, color: Colors.grey),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
